package com.flyxiaozhu.erp.core.entities;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.List;

@Entity
@Data
@DynamicInsert
@DynamicUpdate
@Table(indexes = {
        @Index(columnList = "appId"),
        @Index(columnList = "createTime"),
        @Index(columnList = "status"),
        @Index(columnList = "orderSn", unique = true),
        @Index(columnList = "outTradeNo", unique = true)
})
public class GoodsOrder extends BaseEntity {
    @Column(columnDefinition = "varchar(32) not null default '' comment '订单编号'")
    private String orderSn;

    @Column(columnDefinition = "int(11) not null default 0 comment '应用ID'")
    private long appId;

    @Column(columnDefinition = "varchar(32) not null default '' comment '应用订单号'")
    private String outTradeNo;

    @Column(columnDefinition = "varchar(32) not null default '' comment '应用UID'")
    private String appUid;

    @Column(columnDefinition = "tinyint(2) not null default 0 comment '状态'")
    private int status;

    @Column(columnDefinition = "tinyint(2) not null default 0 comment '发货状态'")
    private int deliveryStatus;

    /*------------收件信息------------*/

    @Column(columnDefinition = "varchar(32) not null default '' comment '手机号码'")
    private String phone;

    @Column(columnDefinition = "int(11) not null default 0 comment '地区代码'")
    private int areaCode;

    @Column(columnDefinition = "varchar(255) not null default '' comment '完整收货地址'")
    private String address;

    @Column(columnDefinition = "varchar(32) not null default '' comment '收件人'")
    private String addressee;

    /*------------价格信息------------*/

    @Column(columnDefinition = "int(11) not null default 0 comment '销售金额'")
    private long sellingAmount;

    @Column(columnDefinition = "int(11) not null default 0 comment '销售总价（含应付运费）'")
    private long totalAmount;

    @Column(columnDefinition = "varchar(32) not null default '' comment '支付方式'")
    private String payCashType;

    @Column(columnDefinition = "int(11) not null default 0 comment '应付运费'")
    private long carriage;

    @Column(columnDefinition = "tinyint(2) not null default 0 comment '是否已支付，0未支付, 1, 99已退款'")
    private int isPaid;

    /*------------其他------------*/

    @Column(columnDefinition = "varchar(255) not null default '' comment '备注'")
    private String remark;

    @Column(columnDefinition = "datetime default null comment '支付时间'")
    private String payTime;

    @Column(columnDefinition = "datetime default null comment '完成时间'")
    private String completeTime;

    @Column(columnDefinition = "datetime default null comment '关闭时间'")
    private String closeTime;

    @Column(columnDefinition = "varchar(255) default null comment '失败信息'")
    private String failedMessage;

    @Column(columnDefinition = "varchar(255) default null comment '管理员备注'")
    private String adminRemark;

    @Transient
    private List<GoodsOrderDetail> details;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn(name = "order_id")
    @OrderBy("create_time DESC")
    private List<GoodsOrderDeliveryLog> deliveryLogs;
}
